import Vue from 'vue'
import App from './App.vue'
import '@/assets/css/bootstrap.css'

Vue.config.productionTip = false

import Vuex from 'vuex';

Vue.use(Vuex)

let store = new Vuex.Store({
  // vuex的配置项
  state: {
    count: 0,
    list: [{
        id: 1,
        task: "吃饭",
        Done: true
      },
      {
        id: 2,
        task: "看胡文帅吃饭",
        Done: true
      },
      {
        id: 3,
        task: "被饭吃掉",
        Done: false
      },
    ]
  },
  mutations: {
    add(state, payload) {
      state.count += payload.num
    },
    sub(state, payload) {
      state.count += payload.num
    }
  },
  actions: {
    addBtn(context) {
      setTimeout(() => {
        context.commit("add", {
          num: 1
        })
      }, 1000);
    },
    subBtn(context) {
      setTimeout(() => {
        context.commit("sub", {
          num: -1
        })
      }, 1000);
    }
  },
  getters: {
    isAll(state) {
      return state.list.every(item => item.Done === true)
    }
  }
})

new Vue({
  render: h => h(App),
  store
}).$mount('#app')